package com.jy.rhin.facade.controller.notification;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.infra.NotificationApplicationService;
import com.jy.rhin.infra.exception.RhinAggrErrorType;
import com.jy.rhin.infra.repo.notfication.participant.query.ParticipantQueryHandler;
import com.jy.rhin.sdk.dto.notification.EditPublisherDto;
import com.jy.rhin.sdk.dto.notification.PublisherDto;
import com.jy.rhin.sdk.dto.notification.PublisherShortDto;
import com.jy.rhin.sdk.dto.notification.req.PublisherOrSubscriberReqDto;
import com.jy.rhin.support.util.Asserts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author dhl
 * @date 2022/6/28
 * @Description 发布者管理api
 */
@RestController
@RequestMapping("/notification/publisher")
@Api(tags = "事件总线api", value = "发布者管理api")
@Slf4j
public class PublisherBizController {
    @Resource
    private NotificationApplicationService notificationApplicationService;
    @Resource
    private ParticipantQueryHandler participantQueryHandler;

    @ApiOperation("发布者管理api-发布者分页查询")
    @GetMapping("/queryPublisherPage")
    public Result<Page<PublisherDto>> queryPublisherPage(PublisherOrSubscriberReqDto dto) {
        return Result.success(participantQueryHandler.queryPublisherPage(dto));
    }

    @ApiOperation("发布者管理api-发布者列表查询")
    @GetMapping("/queryPublisherList")
    public Result<List<PublisherShortDto>> queryPublisherList() {
        return Result.success(participantQueryHandler.queryPublisherList());
    }

    @ApiOperation("发布者管理api-发布者编辑")
    @PostMapping("/editPublisher")
    public Result<String> editPublishes(HttpServletRequest request, @Valid @RequestBody EditPublisherDto dto) {
        String userName = request.getHeader("username");
        Asserts.notEmpty(userName, RhinAggrErrorType.OPERATOR_EMPTY);
        dto.setOperator(userName);
        Long id = notificationApplicationService.editPublisher(dto);
        return Result.success(String.valueOf(id));
    }




}
